package com.gzwanchuang.lszg.module.mine;

import android.graphics.Color;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;


import com.gzwanchuang.lszg.R;
import com.gzwanchuang.lszg.base.BaseActivity;
import com.gzwanchuang.lszg.net.Apis;
import com.gzwanchuang.lszg.net.NetworkManager;
import com.gzwanchuang.lszg.net.interfaces.OnRequestCallBack;
import com.gzwanchuang.lszg.proto.Area;
import com.gzwanchuang.lszg.utils.StatusBarUtil;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

public class FeedBackActivity extends BaseActivity {
    @BindView(R.id.tv_title)
    TextView tvTitle;
    @BindView(R.id.content_et)
    EditText contentEt;
    @BindView(R.id.submit_btn)
    Button submitBtn;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_feed_back);
        ButterKnife.bind(this);
        StatusBarUtil.setStatusBarLightMode(this, Color.parseColor("#ffffff"), true);
        tvTitle.setText("");
    }

    @OnClick({R.id.back_iv, R.id.submit_btn})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.back_iv:
                finish();
                break;
            case R.id.submit_btn:
                submit();
                break;
        }
    }

    private void submit() {
        String s = contentEt.getText().toString();
        if (TextUtils.isEmpty(s)) {
            showToast("请输入反馈内容");
            return;
        }
        Area.area.Builder builder = Area.area.newBuilder();
        builder.setAreaName(s);
        showProgress();
        NetworkManager.INSTANCE.post(Apis.feedback_add, builder.build().toByteArray(), new OnRequestCallBack() {
            @Override
            public void onOk(byte[] response) {
                finish();
            }

            @Override
            public void onError(int code, String errorMessage) {
                showToast(errorMessage);
                hideProgress();
                if (code == 200) {
                    finish();
                }
            }
        });

    }
}
